package com.foreknow.oop10;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class ListDemo {
  public static void main(String[] args) {
    List<Person> list = new ArrayList<>();
    Person p1 = new Person();
    p1.setId("1000");
    p1.setName("tom");
    p1.setAge(30);
    Person p2 = new Person();
    p2.setId("1002");
    p2.setName("tom2");
    p2.setAge(32);

    list.add(p1);
    list.add(p2);

    for (Person person: list) {
      System.out.println(person.getName());
    }

    System.out.println("-----------------------------------");

    //迭代器Iterator:对已知的集合list进行遍历操作
    //hasNext():返回一个boolean表示是否有下一个值
    Iterator<Person> iterator = list.iterator();
    while(iterator.hasNext()){
      Person pp = iterator.next();
      System.out.println(pp.getId());
    }


  }
}
